﻿Imports System.Text
Imports System.Web
Imports System.Web.UI



Public Class Helper

    Public Shared Function convertObjetoCadenaString(ByVal oObjeto() As Object) As String
        Dim Retornar As String = ""
        If Not (oObjeto Is Nothing) Then
            Dim TotalElementos As Int32 = UBound(oObjeto)
            Dim I As Integer = 0
            Retornar = Retornar.Trim()
        End If
        Return Retornar
    End Function

    Public Shared Function convertToDataTable(ByVal DataViewOrigen As DataView) As DataTable
        If Not (DataViewOrigen Is Nothing) Then
            If (DataViewOrigen.Count > 0) Then
                Dim dt As DataTable = DataViewOrigen.Table.Clone
                Dim drNew As DataRow
                For Each drW As DataRowView In DataViewOrigen
                    drNew = dt.NewRow()
                    For C As Integer = 0 To (dt.Columns.Count - 1)
                        drNew(C) = drW.Row(C)
                    Next
                    dt.Rows.Add(drNew)
                Next
                Return dt
            Else
                Return Nothing
            End If
        Else
            Return Nothing
        End If
    End Function

    Public Shared Function encripta(ByVal Pass As String) As String
        Dim Clave As String, i As Integer, Pass2 As String
        Dim CAR As String, Codigo As String
        Clave = "%ü&/@#$A"
        Pass2 = ""
        For i = 1 To Len(Pass)
            CAR = Mid(Pass, i, 1)
            Codigo = Mid(Clave, ((i - 1) Mod Len(Clave)) + 1, 1)
            Pass2 = Pass2 & Right("0" & Hex(Asc(Codigo) Xor Asc(CAR)), 2)
        Next i
        Encripta = Pass2
    End Function

    Public Shared Function desEncripta(ByVal Pass As String) As String
        Dim Clave As String, i As Integer, Pass2 As String
        Dim CAR As String, Codigo As String
        Dim j As Integer
        Clave = "%ü&/@#$A"
        Pass2 = ""
        j = 1
        For i = 1 To Len(Pass) Step 2
            CAR = Mid(Pass, i, 2)
            Codigo = Mid(Clave, ((j - 1) Mod Len(Clave)) + 1, 1)
            Pass2 = Pass2 & Chr(Asc(Codigo) Xor Val("&h" + CAR))
            j = j + 1
        Next i
        DesEncripta = Pass2
    End Function

    Public Shared Sub mensajeAlerta(cp As Page, message As String)
        Dim sb As New StringBuilder()
        sb.Append("<script languaje='javascript'>")
        sb.Append("alert('")
        sb.Append(message)
        sb.Append("')")
        sb.Append("</script>")
        cp.ClientScript.RegisterStartupScript(cp.GetType, "showalert", sb.ToString)
        sb.Remove(0, sb.Length)
    End Sub

    Public Shared Sub mensajeControl(cp As UserControl, message As String)
        Dim sb As New StringBuilder()
        sb.Append("<script languaje='javascript'>")
        sb.Append("alert('")
        sb.Append(message)
        sb.Append("')")
        sb.Append("</script>")
        ScriptManager.RegisterStartupScript(cp, cp.GetType, "showalert", sb.ToString, False)
        sb.Remove(0, sb.Length)
    End Sub

    Public Shared Sub mensajePanel(upi As UpdatePanel, message As String)
        Dim sb As New StringBuilder()
        sb.Append("<script languaje='javascript'>")
        sb.Append("alert('")
        sb.Append(message)
        sb.Append("')")
        sb.Append("</script>")
        ScriptManager.RegisterStartupScript(upi, upi.GetType(), "showalert", sb.ToString, False)
        sb.Remove(0, sb.Length)
    End Sub

End Class
